﻿using System;
using System.Collections.Generic;
using System.Text;
using Torch.WL.Business.Interface;
using Torch.FrameWork.Utility;
using Torch.WL.Business.CleanChina;
using Torch.WL.Entity.CleanChina;

namespace Torch.WL.Business
{
    public class Magazine1Provider : BaseProvider<Magazine1Provider.RequestDataInfo>, IDataProvider
    {
        public Magazine1Provider(string _jsonInfo): base(_jsonInfo)
        {

        }

        public IMessageInfo Do()
        {
            IMessageInfo message = new MessageInfo();
            message.code = (int)MessageCodeType.Success;
            message.message = Utils.GetEnumDescription(MessageCodeType.Success);
            message.data = ProcessResponseData();

            return message;
            
        }

        private List<ResponseDataInfo> ProcessResponseData()
        {
            //use postdata.data to process responseData
            List<ResponseDataInfo> list = new List<ResponseDataInfo>();
            ResponseDataInfo responseData = new ResponseDataInfo();

            List<TbEMEntity> listEM = TbEMManager.Instance().QueryEMByYear(postdata.data.magazine_year);
            
            listEM.ForEach(delegate(TbEMEntity entity){

                list.Add(new ResponseDataInfo() {magazine_id=entity.EMId,year=entity.publishYear, period = "第"+ entity.period.ToString() +"期" });
  
            });

            /*
            responseData.period = "2013年3月";
            list.Add(responseData);

            responseData = new ResponseDataInfo();
            responseData.period = "2013年2月";
            list.Add(responseData);

            responseData = new ResponseDataInfo();
            responseData.period = "2013年1月";
            list.Add(responseData);
            */
            return list;         
        }

        public class RequestDataInfo 
        {
            public int magazine_year { get; set; }
        }

        public class ResponseDataInfo
        {
            public int magazine_id { get; set; }
            public int year { get; set; }
            public string period { get; set; }

        }


    }
}
